package com.ctrip.demo.list;

import org.joda.time.DateTime;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;

public class ListDemo {

    /**
     * @param list
     * @param len
     * @return
     */
    public static <T> List<List<T>> splitList(List<T> list, int len) {
        if (list == null || list.size() == 0 || len < 1) {
            return null;
        }

        List<List<T>> result = new ArrayList<List<T>>();


        int size = list.size();
        int count = (size + len - 1) / len;


        for (int i = 0; i < count; i++) {
            List<T> subList = list.subList(i * len, ((i + 1) * len > size ? size : len * (i + 1)));
            result.add(subList);
        }
        return result;
    }

    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(2);
        list.add(3);
        list.set(0,1);
        System.out.println(list);

        Map<Integer,Integer> map = new HashMap<>();
        map.put(1,1);
        map.put(2,2);
        map.put(3,3);
        Integer remove = map.remove(2);
        System.out.println(remove);

        if (true) {
            System.out.println("第一个");
        }else if (true) {
            System.out.println("第二个");
        }

        DateTime dateTime = DateTime.now().plusSeconds(1);
        Timestamp timestamp = getTimestamp(dateTime);
        System.out.println(timestamp.getTime());
        long time = timestamp.getTime();
        System.out.println(time);
        DateTime dateTime1 = new DateTime(System.currentTimeMillis());
        System.out.println(dateTime1.toString("yyyy/MM/dd"));

        System.out.println(1650425217778L - 1601178296548L);

        System.out.println();

    }

    public static Timestamp getTimestamp(DateTime dateTime){
        // 1601178296548
        long millis = dateTime.toCalendar(Locale.CHINA).getTimeInMillis();
        return new Timestamp(millis);
    }
}
